home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / mobile / fma-2.0-stable-setup.exe / {app} / source / uAccessoriesMenu.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2004-05-19  |  8.8 KB  |  324 lines

  1. unit uAccessoriesMenu;
  2.  
  3. {
  4. *******************************************************************************
  5. * Descriptions: Accessories Menu for Ericsson Phone Implementation
  6. * $Source: /cvsroot/fma/fma/uAccessoriesMenu.pas,v $
  7. * $Locker:  $
  8. *
  9. * Todo:
  10. *
  11. * Change Log:
  12. * $Log: uAccessoriesMenu.pas,v $
  13. * Revision 1.10  2004/05/19 18:34:15  z_stoichev
  14. * Build 0.1.0.35c
  15. *
  16. * Revision 1.9  2004/02/03 16:13:01  z_stoichev
  17. * Fixed Accessories menu Init works in offline mode.
  18. * Fixed am.TxAndWait execute is synced with other TxAndWait calls.
  19. *
  20. * Revision 1.8  2004/01/27 15:54:28  z_stoichev
  21. * menu cleanups.
  22. *
  23. * Revision 1.7  2004/01/23 08:28:16  z_stoichev
  24. * Added missing "
  25. *
  26. * Revision 1.6  2003/12/18 12:45:39  z_stoichev
  27. * Carpedi3m requested implementations.
  28. *
  29. * Revision 1.5  2003/11/28 09:38:07  z_stoichev
  30. * Merged with branch-release-1-1 (Fma 0.10.28c)
  31. *
  32. * Revision 1.4.2.1  2003/10/27 07:22:54  z_stoichev
  33. * Build 0.1.0 RC1 Initial Checkin.
  34. *
  35. * Revision 1.4  2003/07/02 12:43:14  crino77
  36. * added dlginformation
  37. *
  38. * Revision 1.3  2003/01/30 04:15:57  warren00
  39. * Updated with header comments
  40. *
  41. *
  42. *******************************************************************************
  43. }
  44.  
  45. {$WARN SYMBOL_PLATFORM OFF}
  46.  
  47. interface
  48.  
  49. uses
  50.   ComObj, ActiveX, MobileAgent_TLB, StdVcl, Classes, SysUtils;
  51.  
  52. type
  53.   TAccessoriesMenu = class(TAutoObject, IAccessoriesMenu)
  54.   private
  55.     FTitle: String;
  56.     FMenuList: TStrings;
  57.   protected
  58.     procedure Init; safecall;
  59.     procedure Clear; safecall;
  60.     procedure AddItem(const Caption, Event: WideString); safecall;
  61.     procedure Set_Title(const Value: WideString); safecall;
  62.     procedure Set_Selected(Value: Integer); safecall;
  63.     procedure Update; safecall;
  64.     procedure Set_Back(const Value: WideString); safecall;
  65.     procedure ClearMenu; safecall;
  66.     procedure Set_NextState(Value: Integer); safecall;
  67.     procedure DlgOption; safecall;
  68.     procedure DlgMsgBox(const Msg: WideString; TimeoutS: Integer); safecall;
  69.     procedure DlgYesNo(const Msg, Event: WideString; TimeoutS: Integer); safecall;
  70.     procedure DlgOnOff(const Title, Event: WideString; Default: Integer); safecall;
  71.     procedure DlgPercent(const Title, Event: WideString; Steps, Pos: Integer); safecall;
  72.     procedure DlgInputStr(const Title, Prompt: WideString; MaxLen: Integer;
  73.       const DefaultStr: WideString; const Event: WideString); safecall;
  74.     procedure DlgInputInt(const Title, Prompt: WideString; MinVal, MaxVal,
  75.       DefaultVal: Integer; const event: WideString); safecall;
  76.     procedure DlgInformation(const Title, Msg: WideString); safecall;
  77.     procedure DlgFeedback(const Title, event: WideString); safecall;
  78.     { Protected declarations }
  79.   public
  80.     FSelected: Integer;
  81.     FBack: String;
  82.     FEventList: TStrings;
  83.     FNextState: Integer;
  84.     FGeneralEvent: String;
  85.     procedure Initialize; override;
  86.     destructor Destroy; override;
  87.   end;
  88.  
  89. implementation
  90.  
  91. uses ComServ, Unit1;
  92.  
  93. procedure TAccessoriesMenu.Init;
  94. begin
  95.   if Form1.FConnected then Form1.ScheduleTxAndWait('AT*EAM="FMA"');
  96.   Clear;
  97. end;
  98.  
  99. procedure TAccessoriesMenu.Clear;
  100. begin
  101.   ClearMenu;
  102.  
  103.   FTitle := '';
  104.   FSelected := 1;
  105.   FNextState := 1;
  106. end;
  107.  
  108. procedure TAccessoriesMenu.AddItem(const Caption, Event: WideString);
  109. begin
  110.   FMenuList.Add(Caption);
  111.   FEventList.Add(Event);
  112. end;
  113.  
  114. procedure TAccessoriesMenu.Set_Title(const Value: WideString);
  115. begin
  116.   FTitle := Value;
  117. end;
  118.  
  119. procedure TAccessoriesMenu.Set_Selected(Value: Integer);
  120. begin
  121.   FSelected := Value;
  122. end;
  123.  
  124. procedure TAccessoriesMenu.Update;
  125. var
  126.   Com: String;
  127.   Buf, TempBuf: String;
  128.   ComLen, ComCount: Integer;
  129.   i: Integer;
  130. begin
  131.   {
  132.     AT*EASM=<title>,<next_state>,<selected_item>,<number_of_menu_items>[,<menu_item>[,<menu_item>, ...]][,<final_flag>]
  133.   }
  134.  
  135.   Form1.Debug('Updating Accessories Menu');
  136.  
  137.   // Prepare start of AT command
  138.   Com := 'AT*EASM="' + FTitle + '",' + IntToStr(FNextState) + ',' + IntToStr(FSelected) + ',';
  139.   ComLen := Length(Com);
  140.  
  141.   // Reset all flags and buffers
  142.   ComCount := 0;
  143.   Buf := '';
  144.   TempBuf := '';
  145.  
  146.   // Build menu
  147.   for i := 0 to FMenuList.Count - 1 do begin
  148.     // Add menu item
  149.     TempBuf := ',"' + FMenuList.Strings[i] + '"';
  150.     // Check if AT command is not too long
  151.     if (ComLen + Length(Buf) + Length(TempBuf)) > 200 then
  152.     begin
  153.       // It is too long, set final_flag to 0, we will continue
  154.       Buf := Com + IntToStr(ComCount) + Buf + ',0';
  155.       // Send AT command
  156.       Form1.TxAndWait(Buf);
  157.  
  158.       // Store last item to buffer
  159.       Buf := TempBuf;
  160.       ComCount := 1;
  161.     end
  162.     else
  163.     begin
  164.       // Add menu item and increase counter of items in one command
  165.       Buf := Buf + TempBuf;
  166.       Inc(ComCount);
  167.     end;
  168.   end;
  169.  
  170.   // Send rest of menu to phone with final_flag set to 1
  171.   Buf := Com + IntToStr(ComCount) + Buf + ',1';
  172.   Form1.TxAndWait(Buf);
  173. end;
  174.  
  175. procedure TAccessoriesMenu.Set_Back(const Value: WideString);
  176. begin
  177.   FBack := Value;
  178. end;
  179.  
  180. procedure TAccessoriesMenu.ClearMenu;
  181. begin
  182.   FMenuList.Clear;
  183.   FEventList.Clear;
  184.   FBack := '';
  185. end;
  186.  
  187. procedure TAccessoriesMenu.Set_NextState(Value: Integer);
  188. begin
  189.   FNextState := Value;
  190. end;
  191.  
  192. procedure TAccessoriesMenu.DlgOption;
  193. var
  194.   buf: String;
  195.   i: Integer;
  196. begin
  197.   buf := '5,' + IntToStr(FNextState) + ',' + '"' + FTitle + '",' + IntToStr(FSelected) + ',' + IntToStr(FMenuList.Count);
  198.   for i := 0 to FMenuList.Count - 1 do begin
  199.     buf := buf + ',"' + FMenuList.Strings[i] + '"';
  200.   end;
  201.  
  202.   Form1.Debug('Dialog - One of Many');
  203.   Form1.ScheduleTxAndWait('AT*EAID=' + buf);
  204. end;
  205.  
  206. procedure TAccessoriesMenu.DlgMsgBox(const Msg: WideString;
  207.   TimeoutS: Integer);
  208. var
  209.   buf: String;
  210. begin
  211.   buf := '1,' + IntToStr(FNextState) + ',"' + Msg + '"';
  212.   if TimeoutS > 0 then begin
  213.     if TimeoutS > 10 then Exception.Create('TimeoutS out of range (0-10)');
  214.     buf := buf + ',' + IntToStr(TimeoutS * 10);
  215.   end;
  216.  
  217.   Form1.Debug('Dialog - Messagebox');
  218.   Form1.ScheduleTxAndWait('AT*EAID=' + buf);
  219. end;
  220.  
  221. procedure TAccessoriesMenu.DlgYesNo(const Msg, Event: WideString;
  222.   TimeoutS: Integer);
  223. var
  224.   buf: String;
  225. begin
  226.   FGeneralEvent := Event;
  227.  
  228.   buf := '2,' + IntToStr(FNextState) + ',"' + Msg + '"';
  229.   if TimeoutS > 0 then begin
  230.     if TimeoutS > 10 then Exception.Create('TimeoutS out of range (0-10)');
  231.     buf := buf + ',' + IntToStr(TimeoutS * 10);
  232.   end;
  233.  
  234.   Form1.Debug('Dialog - YesNo');
  235.   Form1.ScheduleTxAndWait('AT*EAID=' + buf);
  236. end;
  237.  
  238. procedure TAccessoriesMenu.DlgOnOff(const Title, Event: WideString;
  239.   Default: Integer);
  240. var
  241.   buf: String;
  242. begin
  243.   FGeneralEvent := Event;
  244.  
  245.   buf := '3,' + IntToStr(FNextState) + ',"' + Title + '",' + IntToStr(Default);
  246.   Form1.Debug('Dialog - OnOff');
  247.   Form1.ScheduleTxAndWait('AT*EAID=' + buf);
  248. end;
  249.  
  250. procedure TAccessoriesMenu.DlgPercent(const Title, Event: WideString;
  251.   Steps, Pos: Integer);
  252. var
  253.   buf: String;
  254. begin
  255.   FGeneralEvent := Event;
  256.  
  257.   buf := '4,' + IntToStr(FNextState) + ',"' + Title + '",' + IntToStr(Steps) + ',' + IntToStr(pos);
  258.   Form1.Debug('Dialog - Percent');
  259.   Form1.ScheduleTxAndWait('AT*EAID=' + buf);
  260. end;
  261.  
  262. procedure TAccessoriesMenu.DlgInputStr(const Title, Prompt: WideString; MaxLen: Integer;
  263.   const DefaultStr: WideString; const Event: WideString);
  264. var
  265.   buf: String;
  266. begin
  267.   FGeneralEvent := Event;
  268.  
  269.   buf := '11,' + IntToStr(FNextState) + ',"' + Title + '","' + Prompt + '",' + IntToStr(maxLen) + ',"' + DefaultStr + '"';
  270.   Form1.Debug('Dialog - InputStr');
  271.   Form1.ScheduleTxAndWait('AT*EAID=' + buf);
  272. end;
  273.  
  274. procedure TAccessoriesMenu.DlgInputInt(const Title, Prompt: WideString;
  275.   MinVal, MaxVal, DefaultVal: Integer; const event: WideString);
  276. var
  277.   buf: String;
  278. begin
  279.   FGeneralEvent := Event;
  280.  
  281.   buf := '7,' + IntToStr(FNextState) + ',"' + Title + '","' + Prompt + '",' + IntToStr(MinVal) + ',' + IntToStr(MaxVal) + ',' + IntToStr(DefaultVal);
  282.   Form1.Debug('Dialog - InputInt');
  283.   Form1.ScheduleTxAndWait('AT*EAID=' + buf);
  284. end;
  285.  
  286. procedure TAccessoriesMenu.DlgInformation(const Title, Msg: WideString);
  287. var
  288.   buf: String;
  289. begin
  290.   buf := '14,' + IntToStr(FNextState) + ',"' + Title + '","' + Msg + '"';
  291.   Form1.Debug('Dialog - Information');
  292.   Form1.ScheduleTxAndWait('AT*EAID=' + buf);
  293. end;
  294.  
  295. procedure TAccessoriesMenu.DlgFeedback(const Title, event: WideString);
  296. var
  297.   buf: String;
  298. begin
  299.   FGeneralEvent := Event;
  300.  
  301.   buf := '13,' + IntToStr(FNextState) + ',"' + Title + '"';
  302.   Form1.Debug('Dialog - Feedback');
  303.   Form1.ScheduleTxAndWait('AT*EAID=' + buf);
  304. end;
  305.  
  306. destructor TAccessoriesMenu.Destroy;
  307. begin
  308.   FreeAndNil(FMenuList);
  309.   FreeAndNil(FEventList);
  310.   inherited;
  311. end;
  312.  
  313. procedure TAccessoriesMenu.Initialize;
  314. begin
  315.   inherited;
  316.   FMenuList := TStringList.Create;
  317.   FEventList := TStringList.Create;
  318. end;
  319.  
  320. initialization
  321.   TAutoObjectFactory.Create(ComServer, TAccessoriesMenu, Class_AccessoriesMenu,
  322.     ciMultiInstance, tmApartment);
  323. end.
  324.